//
//  YMJNetWorking.m
//  检测网络单例
//
//  Created by 殷殷明静 on 16/9/23.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "YMJNetWorking.h"

@implementation YMJNetWorking
+ (instancetype)shareNetWorking {
    static YMJNetWorking *gns = nil;
    static dispatch_once_t onceToken;
    if (gns == nil) {
        dispatch_once(&onceToken, ^{
            gns = [[YMJNetWorking alloc] init];
        });
    }
    return gns;
}
- (BOOL)updateInterfaceWithReachability {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
    self.internetReachability = [Reachability reachabilityForInternetConnection];
    [self.internetReachability startNotifier];
    NetworkStatus netStatus = [self.internetReachability currentReachabilityStatus];
    switch (netStatus) {
        case NotReachable:
            NSLog(@"亲,你的网络飞走了,快把它追回来");
            return NO;
            break;
        case ReachableViaWiFi:
            NSLog(@"当前网络状态为Wifi");
            return YES;
            break;
        case ReachableViaWWAN:
            NSLog(@"当前网络状态为3G");
            return YES;
            break;
    }
}
- (void) reachabilityChanged:(NSNotification *)note
{
    Reachability* curReach = [note object];
    NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
    [self updateInterfaceWithReachability];
}

@end
